package com.ymm.system.core.testController;

import com.ymm.system.core.config.websocket.WebSocket;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Author zikang.yao
 * @Description TODO
 * @Date 2022/8/9 16:49
 * @Version 1.0
 */
@Controller
@RequestMapping("/qqq")
public class WebSocketTestController {

        @Resource
        private WebSocket webSocket;

        /**
         * 页面文件入口
         */
        @GetMapping("/index")
        public String index() {
            return "index";
        }

        /**
         * 发送场景模拟
         *
         * @param msg
         * @return
         */
        @GetMapping("/test")
        @ResponseBody
        public String sendMessage(String msg) {
            //如果访问的地址中msg参数不为空值，发送msg的值给前端
            if (!StringUtils.isEmpty(msg)) {
                webSocket.sendMessage(msg);
                return msg;
            }
            return "服务端未发送消息msg：" + msg;
        }
    }


